package com.briup.cms.web.controller;

import com.briup.cms.bean.Facility;
import com.briup.cms.service.IFacilityService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "设施管理")
@RestController
@RequestMapping("/auth/facility")

public class FacilityController {
    private final IFacilityService facilityService;

    public FacilityController(IFacilityService facilityService) {
        this.facilityService = facilityService;
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true,paramType = "query"),
            @ApiImplicitParam(name = "keywords",value = "用户名关键字",paramType = "query"),
    })
    @GetMapping("/pageQuery")
    private Message pageQuery(int pageNum,int pageSize, String keywords){
        PageInfo<Facility> data =facilityService.pageQuery(pageNum,pageSize,keywords);
        return MessageUtil.success(data);
    }

    @ApiOperation("查询所有")
    @GetMapping("findAll")
    public Message findAll(){
        List<Facility>list=facilityService.findAll();
        return MessageUtil.success(list);
    }

    @ApiOperation("保存或更新")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Facility facility){
        facilityService.saveOrUpdate(facility);
        return MessageUtil.success(facility);
    }
    @ApiOperation(value="批量删除设施")
    @DeleteMapping(value="/batchDelete")
    public Message batchDelete(int[] ids) {
        facilityService.batchDelete(ids);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value="根据ID删除设施")
    @DeleteMapping(value="/deleteById")
    public Message deleteById(int id) {
        facilityService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value="设施审核",notes="status状态：0-待审核，1-不通过，2-通过")
    @PutMapping(value="/check")
    public Message check(int id,int status) {
        facilityService.checkFacility(id, status);
        return MessageUtil.success("操作成功");
    }
}
